//
//  SubscribeTableViewCell.m
//  MXClassroom
//
//  Created by 你个LB on 16/9/11.
//  Copyright © 2016年 你个LB. All rights reserved.
//

#import "SubscribeTableViewCell.h"

@implementation SubscribeTableViewCell

/** 初始化方法 */
+ (instancetype)cellWithTableView:(UITableView *)tableView{
    static NSString * reuseIdentifier = @"identifier";
    SubscribeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
    if (cell == nil) {
        // 创建cell
        cell = [[SubscribeTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
    }
    return cell;
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // 图标
        _headImgView = [[UIImageView alloc] initWithFrame:CGRectMake(8, 13, 60, 60)];
//        _headImgView.backgroundColor = [UIColor redColor];
        [self.contentView addSubview:_headImgView];
        
        // 标题
        _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(_headImgView.right + 16, 13, 200, 13)];
        _titleLabel.textColor = kColor_text_color;
        _titleLabel.font = [UIFont systemFontOfSize:13 weight:2];
//        _titleLabel.backgroundColor = [UIColor redColor];
        [self.contentView addSubview:_titleLabel];
        
        // 最新课时
        _newestClassHourLabel = [[UILabel alloc] initWithFrame:CGRectMake(_headImgView.right + 16, _titleLabel.bottom + 16, 200, 11)];
        _newestClassHourLabel.textColor = kColor_text_color;
        _newestClassHourLabel.font = [UIFont systemFontOfSize:11];
//        _newestClassHourLabel.backgroundColor = [UIColor redColor];
        [self.contentView addSubview:_newestClassHourLabel];
        
        // 讲解时间
        _teachTimeLabel = [[UILabel alloc] initWithFrame:CGRectMake(_headImgView.right + 16, 0, 60, 11)];
        _teachTimeLabel.bottom = _headImgView.bottom;
        _teachTimeLabel.textColor = kColor_text_color;
        _teachTimeLabel.font = [UIFont systemFontOfSize:11];
//        _teachTimeLabel.backgroundColor = [UIColor redColor];
        [self.contentView addSubview:_teachTimeLabel];
        
        // 讲师
        _teacherLabel = [[UILabel alloc] initWithFrame:CGRectMake(_teachTimeLabel.right + 4, 0, 100, 11)];
        _teacherLabel.bottom = _headImgView.bottom;
        _teacherLabel.textColor = kColor_text_color;
        _teacherLabel.font = [UIFont systemFontOfSize:11 weight:2];
//        _teacherLabel.backgroundColor = [UIColor redColor];
        [self.contentView addSubview:_teacherLabel];
        
        // 订阅按钮
        UIButton * subscribeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        subscribeBtn.frame = CGRectMake(kScreen_width - 80 - 8, 8, 80, 30);
        [subscribeBtn setImage:[UIImage imageNamed:@"icon_main_feed_cancel_normal.png"] forState:UIControlStateNormal];
        [subscribeBtn setImage:[UIImage imageNamed:@"icon_main_feed_cancel_pressed.png"] forState:UIControlStateHighlighted];
        [self.contentView addSubview:subscribeBtn];
    }
    return self;
}

- (void)setSubscribe:(SubscribeModel *)subscribe{
    if (_subscribe != subscribe) {
        _subscribe = subscribe;
        
        // 为控件设置数据
        _headImgView.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@",subscribe.headImg]];
        
        _titleLabel.text = subscribe.title;
        
        _newestClassHourLabel.text = [NSString stringWithFormat:@"最新课时:%@",subscribe.newestClassHour];
        
        _teachTimeLabel.text = subscribe.teachTime;
        
        _teacherLabel.text = [NSString stringWithFormat:@"by %@",subscribe.teacher];
    }
}

@end
